package com.xintai.system.controller;

import java.util.List;

import com.xintai.system.domain.PubWorkshop;
import com.xintai.system.service.impl.ErpJingbanrenServiceImpl;
import com.xintai.utils.StaticString;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.system.domain.ErpJingbanren;
import com.xintai.system.service.IErpJingbanrenService;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * 经办人Controller
 * 
 * @author xintai
 * @date 2021-01-10
 */
@RestController
@RequestMapping("/system/jingbanren")
public class ErpJingbanrenController extends BaseController
{
    @Autowired
    private IErpJingbanrenService erpJingbanrenService;

    /**
     * 查询经办人列表
     */
    @PreAuthorize("@ss.hasPermi('system:jingbanren:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpJingbanren erpJingbanren)
    {
        startPage();
        List<ErpJingbanren> list = erpJingbanrenService.selectErpJingbanrenList(erpJingbanren);
        return getDataTable(list);
    }

    /**
     * 导出经办人列表
     */
    @PreAuthorize("@ss.hasPermi('system:jingbanren:export')")
    @Log(title = "经办人", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ErpJingbanren erpJingbanren)
    {
        List<ErpJingbanren> list = erpJingbanrenService.selectErpJingbanrenList(erpJingbanren);
        ExcelUtil<ErpJingbanren> util = new ExcelUtil<ErpJingbanren>(ErpJingbanren.class);
        return util.exportExcel(list, "jingbanren");
    }

    /**
     * 获取经办人详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:jingbanren:query')")
    @GetMapping(value = "/{jbrId}")
    public AjaxResult getInfo(@PathVariable("jbrId") Integer jbrId)
    {
        return AjaxResult.success(erpJingbanrenService.selectErpJingbanrenById(jbrId));
    }

    /**
     * 新增经办人
     */
    @PreAuthorize("@ss.hasPermi('system:jingbanren:add')")
    @Log(title = "经办人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpJingbanren erpJingbanren)
    {
        if (erpJingbanrenService.verifyErpJingBanRen(erpJingbanren))
            return AjaxResult.error(StaticString.NameRepeat(erpJingbanren.getJbrName()));
        return toAjax(erpJingbanrenService.insertErpJingbanren(erpJingbanren));
    }

    /**
     * 修改经办人
     */
    @PreAuthorize("@ss.hasPermi('system:jingbanren:edit')")
    @Log(title = "经办人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpJingbanren erpJingbanren)
    {
        if (erpJingbanrenService.verifyErpJingBanRen(erpJingbanren))
            return AjaxResult.error(StaticString.NameRepeat(erpJingbanren.getJbrName()));
        return toAjax(erpJingbanrenService.updateErpJingbanren(erpJingbanren));
    }

    /**
     * 删除经办人
     */
    @PreAuthorize("@ss.hasPermi('system:jingbanren:remove')")
    @Log(title = "经办人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jbrIds}")
    public AjaxResult remove(@PathVariable Integer[] jbrIds)
    {
        return toAjax(erpJingbanrenService.deleteErpJingbanrenByIds(jbrIds));
    }
}
